#include "BDTestBase.h"
#include "BDTime.h"



DECLARE_TEST_VAR(Test_5)
{
	bool update = true;
	int correctColor = -1;
	BDVector<int> indexs;
	int reactionTime = 0;
	int rightTimes = 0;
	int totolTimes = 0;
	BDTime m_Time;
};

DECLARE_TEST_N(Test_5, BDTestBase, 3)

DECLARE_EXAMPLE(Test_5)
{

	if (TEST_VAR(update)) {
		TEST_VAR(update) = false;
		TEST_VAR(m_Time).Start();
		BDTestUtils::Random(TEST_VAR(indexs), 3);
	}

	AllocPainterParamShape(6);
	for (int i = 0; i < TEST_VAR(indexs).size(); ++i) {
		GetPainterParamShape(2 * i)->set_type(PainterRefreshParam_Shape_ShapeType_SHAPE_IMAGE);
		GetPainterParamShape(2 * i)->mutable_image()->set_test_name(GetTestName());
		GetPainterParamShape(2 * i)->mutable_image()->set_example(m_Times);
		GetPainterParamShape(2 * i)->mutable_image()->set_id(TEST_VAR(indexs)[i]);
		GetPainterParamShape(2 * i)->mutable_image()->set_x(400 * i);
		GetPainterParamShape(2 * i)->mutable_image()->set_y(20);
		GetPainterParamShape(2 * i)->mutable_image()->set_size(50);

		GetPainterParamShape(2 * i + 1)->set_type(PainterRefreshParam_Shape_ShapeType_SHAPE_CIRCLE);
		GetPainterParamShape(2 * i + 1)->mutable_circle()->set_x(400 * i +100);
		GetPainterParamShape(2 * i + 1)->mutable_circle()->set_y(500);
		GetPainterParamShape(2 * i + 1)->mutable_circle()->set_r(50);
		GetPainterParamShape(2 * i + 1)->mutable_circle()->set_line_color(PainterRefreshParam_Shape_Color_COLOR_BLACK);
		GetPainterParamShape(2 * i + 1)->mutable_circle()->set_fill_color(static_cast<PainterRefreshParam_Shape_Color>(i + 3));

		if (TEST_VAR(indexs)[i] == 0) {
			TEST_VAR(correctColor) = i;
		}
	}

	if (GetButtonIsDown()) {
		if (GetButtonIsDown(TEST_VAR(correctColor))) {
			TEST_VAR(rightTimes)++;
			TEST_VAR(totolTimes)++;
		}
		else {
			TEST_VAR(totolTimes)++;
		}
		ClearButton();
		TEST_VAR(reactionTime) = TEST_VAR(m_Time).Elapsed();
		TEST_VAR(update) = true;
		NextExample();
	}

	AllocDetailParamItem(4);
	GetDetailParamItem(0)->set_key("Reaction Time");
	ostringstream os0;
	os0 << TEST_VAR(reactionTime);
	GetDetailParamItem(0)->set_value(os0.str());

	GetDetailParamItem(1)->set_key("Attention");
	ostringstream os1;
	os1 << m_iAttention;
	GetDetailParamItem(1)->set_value(os1.str());

	GetDetailParamItem(2)->set_key("Right Times");
	ostringstream os2;
	os2 << TEST_VAR(rightTimes);
	GetDetailParamItem(2)->set_value(os2.str());

	GetDetailParamItem(3)->set_key("Total Times");
	ostringstream os3;
	os3 << TEST_VAR(totolTimes);
	GetDetailParamItem(3)->set_value(os3.str());

	Notify();
}
